import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home/Home.vue'

Vue.use(VueRouter)

import routes from "./users"
const router = new VueRouter({
        routes
    })
    // 路由守卫
router.beforeEach((to, form, next) => {
    //to:即将进入的目标
    //from:即将离开的路由
    // next：放行
    var token = window.sessionStorage.getItem("token");
    if (to.path == "/admin/login") {
        next();
        return;
    }
    //如果token不存在，跳转到登录页面
    if (!token) return next("/admin/login");
    next();
})
export default router